#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 5;
int t, n;
int p[N];
string s;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;
    while (t--) {
        cin >> n;

        map<int, int> rk0, rk1;
        for (int i = 0; i < n; i++) {
            cin >> p[i];
        }
        string s;
        cin >> s;
        for (int i  = 0; i < n; i++) {
            if (s[i] == '0') rk0[-p[i]] = i;
            else rk1[-p[i]] = i;
        }
        vector<int> ans(n + 1, 0);

        int temp = n;
        for (auto [k, v] : rk1) {
            ans[v+1] = temp--;
        }
        for (auto [k, v] : rk0) {
            ans[v+1] = temp--;
        }

        for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
        cout << endl;


    }
    return 0;
}